<?php
!defined('DEBUG') AND exit('Forbidden');
$tablepre = $db->tablepre;
$msg = [];
$sql = "DROP TABLE IF EXISTS {$tablepre}reward;";
$r = db_exec($sql);
$r === FALSE AND $msg[] = "Failed to delete the {$tablepre}reward table";
// group表中所有需要删除的列
$columns_to_drop = ['reward_from1','reward_from2','reward_from3','reward_to1','reward_to2','reward_to3','have_reward'];
$sqls = [];
$columns_sql = "SHOW COLUMNS FROM `{$tablepre}group`;";// 列出字段
$has_columns = db_sql_find($columns_sql, 'Field');
if (!empty($has_columns)) {
    foreach ($columns_to_drop as $column) {
        if(isset($has_columns[$column])){// 如果列存在，则添加到ALTER TABLE语句中
            $sqls[$column] = "ALTER TABLE `{$tablepre}group` DROP `{$column}`;";
        }
    }
}
foreach ($sqls as $column => $sql){
    $r2 = db_exec($sql);
    $r2 === FALSE AND $msg[] = "Failed to delete {$column} field in the {$tablepre}group table";
}
setting_delete('tt_reward');
group_list_cache_delete();
if(!empty($msg)) message(1,$msg);//显示错误信息
?>